package br.com.abril.task;

import org.apache.log4j.Logger;

import br.com.abril.job.AbstractTask;

import com.force.abril.executive.prevision.ExecutivePrevisionServiceActivator;
import com.sforce.ws.ConnectionException;

public class ExecutivePrevisionTask extends AbstractTask {

	private DownloadFineshedEventPublisher publisher;
	
	private static final Logger logger = Logger
			.getLogger(ExecutivePrevisionTask.class);

	private ExecutivePrevisionServiceActivator service;

	public ExecutivePrevisionTask() {
		service = applicationContext
				.getBean(ExecutivePrevisionServiceActivator.class);
		
		publisher = applicationContext
				.getBean(DownloadFineshedEventPublisher.class);
	}

	@Override
	public void execute() {
		try {
			service.downloadPrevisions();
			
			logger.info("................ Download Executive Prevision completed");
			
			publisher.publish();
			
			logger.info("................ Published Completed");

		} catch (ConnectionException e) {
			logger.error("Unable to Connect to SalesForce", e);
		}
	}

}
